<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>聊天API测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .container {
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        button {
            padding: 8px 16px;
            cursor: pointer;
        }
        textarea {
            width: 100%;
            min-height: 100px;
        }
        .response {
            border: 1px solid #ddd;
            padding: 10px;
            min-height: 200px;
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>
    <h1>聊天API测试</h1>
    <div class="container">
        <div>
            <h3>测试 /v1/chat 接口</h3>
            <textarea id="message" placeholder="输入测试消息...">你好，这是一个测试消息</textarea>
            <button onclick="testChatApi()">发送请求</button>
            <div class="response" id="response">等待响应...</div>
        </div>
    </div>
    
    <script>
        async function testChatApi() {
            const message = document.getElementById('message').value;
            const responseDiv = document.getElementById('response');
            
            responseDiv.innerHTML = '正在发送请求...';
            
            try {
                const response = await fetch('http://127.0.0.1:8001/v1/chat', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        session_id: 'test_session',
                        message: message,
                        use_rag: false,
                        use_tools: false,
                        stream: false
                    })
                });
                
                const data = await response.json();
                
                responseDiv.innerHTML = `状态码: ${response.status}<br>`;
                responseDiv.innerHTML += `响应数据: ${JSON.stringify(data, null, 2)}<br>`;
                
                if (data.content) {
                    responseDiv.innerHTML += `<br><strong>AI回复:</strong> ${data.content}`;
                }
            } catch (error) {
                responseDiv.innerHTML = `请求失败: ${error.message}`;
                console.error('API请求错误:', error);
            }
        }
    </script>
</body>
</html>